﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

using Point = System.Drawing.Point;
using Iterators;

namespace LowLevelGraphics
{
    public class PointCloud
    {
        public Rectangle GetBoundingRectangle(IEnumerable<Point> _points)
        {
            Rectangle rectangle = Rectangle.Empty;

            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach (Point pt in _points)
            {
                int x = pt.X;
                int y = pt.Y;

                // check X coordinate
                if (x < minX)
                    minX = x;
                if (x > maxX)
                    maxX = x;

                // check Y coordinate
                if (y < minY)
                    minY = y;
                if (y > maxY)
                    maxY = y;
            }

            if (minX > maxX) // no point is set to max
                throw new ArgumentException("Empty point list.");

            rectangle = Rectangle.FromLTRB(minX, minY, maxX, maxY);
            return rectangle;
        }

        public void Move(IList<Point> _points, Point _ptShift)
        {
            int nIndex = 0;
            foreach (var item in _points)
            {
                _points[nIndex] = System.Drawing.Point.Add(_points[nIndex], new Size((int)_ptShift.X, (int)_ptShift.Y));
                nIndex++;
            }
        }
    }
}
